# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=libheif
pkgver=1.17.6
pkgrel=1
pkgdesc="ISO/IEC 23008-12:2017 HEIF file format decoder and encoder"
url="https://www.libde265.org/"
arch="all"
license="LGPL-3.0-or-later"
depends_dev="
	libde265-dev
	x265-dev
	"
makedepends="
	$depends_dev
	aom-dev
	cmake
	libjpeg-turbo-dev
	libpng-dev
	gdk-pixbuf-dev
	samurai
	"
options="!check"  # no tests provided
subpackages="
	$pkgname-dev
	heif-thumbnailer
	$pkgname-tools
	$pkgname-doc
	$pkgname-pixbuf-loader
	"
source="https://github.com/strukturag/libheif/releases/download/v$pkgver/libheif-$pkgver.tar.gz"

# secfixes:
#   1.17.6-r0:
#     - CVE-2023-49462
#     - CVE-2023-49463
#   1.5.0-r0:
#     - CVE-2019-11471

build() {
	# This is en/decoder, so performance matters more than size.
	export CPPFLAGS="${CFLAGS/-Os/-O2}"
	export CXXFLAGS="${CFLAGS/-Os/-O2} -flto=auto"

	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_SKIP_INSTALL_RPATH=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

thumbnailer() {
	pkgdesc="$pkgdesc (thumbnailer)"

	amove usr/bin/heif-thumbnailer
}

tools() {
	pkgdesc="$pkgdesc (tools)"
	depends="heif-thumbnailer=$pkgver-r$pkgrel"

	amove usr/bin
}

loader() {
	pkgdesc="$pkgdesc (pixbuf loader)"
	depends="heif-thumbnailer=$pkgver-r$pkgrel"
	install_if="$pkgname=$pkgver-r$pkgrel gdk-pixbuf-loaders"

	amove \
		usr/lib/gdk-pixbuf-*/*/loaders \
		usr/share/thumbnailers
}

sha512sums="
47d93df4f584979cea26af74cd8543b13398356b5fd46b1b378f7738cee471e80b7e117f6ce307674a549182f5ce22a577c6e79a6e72fe166421efc4be04687a  libheif-1.17.6.tar.gz
"
